package com.syp.hehe.util;

import java.util.Enumeration;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Description: 属性文件工具类
 * 
 * @author syp
 * 
 */
public  class PropertiesUtil {

	private static final Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);

	/* 系统配置*/
	public static final ConcurrentMap<String, String> sysConfigMap = new ConcurrentHashMap<String, String>();
	
	static {
		try {
			init();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * Description: 初始化方法
	 * 
	 * @throws Exception
	 */
	private static void init() throws Exception {
		try{
            ResourceBundle sys_config_bundle = ResourceBundle
                    .getBundle("prop/sys_config");
            initBundle(sys_config_bundle, sysConfigMap);
		}catch(Exception e){
			logger.error("properties init error", e);
		}
	}

    private static void initBundle(ResourceBundle bundle,ConcurrentMap<String, String> map){
		Enumeration<String> e = bundle.getKeys();
		while (e.hasMoreElements()) {
			String key = e.nextElement();
			map.put(key, bundle.getString(key));
		}
	}
}
